package com.hckjsec.system.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.system.domain.SysPaper;
import com.hckjsec.system.service.ISysPaperService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 论文管理Controller
 * 
 * @author cyt
 * @date 2021-10-11
 */
@RestController
@RequestMapping("/system/paper")
public class SysPaperController extends BaseController
{
    @Autowired
    private ISysPaperService sysPaperService;

    /**
     * 查询论文管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysPaper sysPaper)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            sysPaper.setDeptId(SecurityUtils.getDeptId());
        }
        List<SysPaper> list = sysPaperService.selectSysPaperList(sysPaper);
        return getDataTable(list);
    }

    /**
     * 导出论文管理列表
     */
    @Log(title = "论文管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysPaper sysPaper)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            sysPaper.setDeptId(SecurityUtils.getDeptId());
        }
        List<SysPaper> list = sysPaperService.selectSysPaperList(sysPaper);
        ExcelUtil<SysPaper> util = new ExcelUtil<SysPaper>(SysPaper.class);
        return util.exportExcel(list, "paper");
    }

    /**
     * 获取论文管理详细信息
     */
    @GetMapping(value = "/{paperId}")
    public AjaxResult getInfo(@PathVariable("paperId") Long paperId)
    {
        return AjaxResult.success(sysPaperService.selectSysPaperById(paperId));
    }

    /**
     * 新增论文管理
     */
    @Log(title = "论文管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPaper sysPaper)
    {
        sysPaper.setDeptId(SecurityUtils.getDeptId());
        sysPaper.setOperator(SecurityUtils.getUserId());
        return toAjax(sysPaperService.insertSysPaper(sysPaper));
    }

    /**
     * 修改论文管理
     */
    @Log(title = "论文管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPaper sysPaper)
    {
        return toAjax(sysPaperService.updateSysPaper(sysPaper));
    }

    /**
     * 删除论文管理
     */
    @Log(title = "论文管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paperIds}")
    public AjaxResult remove(@PathVariable Long[] paperIds)
    {
        return toAjax(sysPaperService.deleteSysPaperByIds(paperIds));
    }
}
